#include "AddBlockToPieceNetworkEvent.h"
#include "Piece.h"

AddBlockToPieceNetworkEvent::AddBlockToPieceNetworkEvent(long pieceId, long blockId, const Position& position)
{
    message.header.code = NetworkEvent::SERVER_ADD_BLOCK_TO_PIECE;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.pieceId = pieceId;
    message.data.blockId = blockId;
    message.data.x = position.x;
    message.data.y = position.y;
}

AddBlockToPieceNetworkEvent::AddBlockToPieceNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

AddBlockToPieceNetworkEvent::~AddBlockToPieceNetworkEvent()
{
}

void* AddBlockToPieceNetworkEvent::getMessageBlob()
{
    return &message;
}

void AddBlockToPieceNetworkEvent::visitPiece(Piece* piece) const
{
    piece->handleAddBlockToPieceEvent(message.data.pieceId, message.data.blockId,
            Position(message.data.x, message.data.y));
}

size_t AddBlockToPieceNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}
